<template>
    <el-form :model="form" label-width="auto" :inline="true">
        <div>

            <el-form-item label="转舍日期" style="width: 450px;">
                <el-col :span="11">
                    <el-date-picker v-model="form.transferDate" type="date" placeholder="请选择" style="width: 100%" />
                </el-col>
                <el-col :span="11">
                    <el-date-picker v-model="form.jTransferDate" type="date" placeholder="请选择" style="width: 100%" />
                </el-col>
            </el-form-item>
            <el-form-item label="羊只耳号" style="width: 200px;">
                <el-select v-model="form.breedingSheepArchiveId" placeholder="请选择">
                    <el-option v-for="a in bugles" :label="a.auricle" :value="a.breedingSheepArchiveId" />
                </el-select>
            </el-form-item>
            <el-form-item label="栋舍类型" style="width: 200px;">
                <el-select v-model="form.buildingTypeId" placeholder="请选择">
                    <el-option v-for="a in building" :label="a.buildingTypeName" :value="a.buildingTypeId" />
                </el-select>
            </el-form-item>
            <el-form-item label="转出栋舍" style="width: 200px;">
                <el-select v-model="form.buildingsOut" placeholder="请选择">
                    <el-option v-for="a in buildingList" :label="a.buildingName" :value="a.buildingId"
                        @click="getcolumnsOu()" />
                </el-select>
            </el-form-item>
            <el-form-item label="转出栏位" style="width: 200px;">
                <el-select v-model="form.columnsOut" placeholder="请选择">
                    <el-option v-for="a in columnsO" :label="a.columnsName" :value="a.columnsId" />
                </el-select>
            </el-form-item>
            <el-form-item label="转入栋舍" style="width: 200px;">
                <el-select v-model="form.buildingsEnter" placeholder="请选择">
                    <el-option v-for="a in buildingList" :label="a.buildingName" :value="a.buildingId"
                        @click="getcolumnsOut()" />
                </el-select>
            </el-form-item>
            <el-form-item label="转入栏位" style="width: 200px;">
                <el-select v-model="form.columnsEnter" placeholder="请选择">
                    <el-option v-for="a in columnsOu" :label="a.columnsName" :value="a.columnsId" />
                </el-select>
            </el-form-item>
        </div>
    </el-form>

    <el-button type="success" @click="getlist()">查询</el-button>
    <el-table :data="list" style="width: 100%">
        <el-table-column prop="transferId" label="序号" />
        <el-table-column prop="transferDate" label="转舍日期">
            <template v-slot="scope">
                {{ scope.row.transferDate.substring(0, 10) }}
            </template>
        </el-table-column>
        <el-table-column prop="auricle" label="羊只耳号" />
        <el-table-column prop="buildingTypeName" label="转舍类型" />
        <el-table-column prop="buildingName" label="转出栋舍" />
        <el-table-column prop="columnsName" label="转出栏位" />
        <el-table-column prop="bEnter" label="转入栋舍" />
        <el-table-column prop="cEnter" label="转入栏位" />
        <el-table-column prop="sheepvarietyName" label="品种" />
        <el-table-column prop="transferSex" label="性别">
            <template v-slot="scope">
                <span v-if="scope.row.transferSex == 1">公</span>
                <span v-else>母</span>
            </template>
        </el-table-column>
    </el-table>
</template>
<script setup lang="ts">
import { reactive, ref, onMounted } from 'vue'
import axios from 'axios';
const form = reactive({
    transferDate: "",
    jTransferDate: "",
    breedingSheepArchiveId: "",
    buildingTypeId: "",
    buildingsOut: "",
    columnsOut: "",
    buildingsEnter: "",
    columnsEnter: ""

})
const formm = reactive({
    totalCount: 0,
    pageCount: 0,
})

//栏位-下拉框
const columnsOu = ref([])
const getcolumnsOut = () => {
    axios.post("http://localhost:5012/api/Buildings/ColumnsList", {
        buildingId: form.buildingsEnter
    }).then(res => {
        columnsOu.value = res.data.data
    })
}
//转出栏位-下拉框
const columnsO = ref([])
const getcolumnsOu = () => {
    axios.post("http://localhost:5012/api/Buildings/ColumnsList", {
        buildingId: form.buildingsOut
    }).then(res => {
        columnsO.value = res.data.data
    })
}

//栋舍管理—显示
const buildingList = ref([]);
const getBuildingList = () => {
    axios
        .post("http://localhost:5012/api/Buildings/BuildingList", {
            buildingTypeId: 0,
            buildingName: '',
            buildingPerson: '',
            pageSize: 5,
            pageIndex: 1,
        })
        .then((res) => {
            console.log(res.data.data);
            buildingList.value = res.data.data.data;
            formm.pageCount = res.data.data.pageCount;
            formm.totalCount = res.data.data.totalCount;
        })
        .catch((err) => {
            console.log(err);
        });
};
//栋舍类型
const building = ref([])
const getbuilding = () => {
    axios.post("http://localhost:5012/api/Buildings/BuildingTypeBind", {}).then(res => {
        console.log(res)
        building.value = res.data.data
    })
}
//耳号下拉框
const bugles = ref([])
const getsheepvariety = () => {
    axios.post("http://localhost:5012/api/SheepFile/BasicInformationList", {}).then(res => {
        console.log(res)
        bugles.value = res.data.data
    })
}
const list = ref([])
const getlist = () => {
    axios.post("http://localhost:5012/api/Prompt/transferList", {
        transferDate: form.transferDate,
        jTransferDate: form.jTransferDate,
        breedingSheepArchiveId: form.breedingSheepArchiveId || 0,
        buildingTypeId: form.buildingTypeId || 0,
        buildingsOut: form.buildingsOut || 0,
        columnsOut: form.columnsOut || 0,
        buildingsEnter: form.buildingsEnter || 0,
        columnsEnter: form.columnsEnter || 0
    }).then(res => {
        list.value = res.data.data
    })
}
onMounted(() => {
    getlist()
    getsheepvariety()
    getbuilding()
    getcolumnsOu()
    getBuildingList()
})
</script>